home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo3.zoo / demo / misc / show.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-25  |  3.2 KB  |  133 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: show.c,v 4.4 88/09/14 11:21:13 bianchi Exp $
  9.     $Source: /fs/16/21272/bianchi/src/nmgr/demo/misc/RCS/show.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /fs/16/21272/bianchi/src/nmgr/demo/misc/RCS/show.c,v $$Revision: 4.4 $";
  12.  
  13. /* show a dithered image on a mgr window  (binary input) */
  14.  
  15. #include <stdio.h>
  16. #include <sgtty.h>
  17. #include <signal.h>
  18. #include "term.h"
  19. #include "dump.h"
  20.  
  21. #define Min(x,y)    ((x)>(y)?y:x)
  22. #define GET_OPT(i)    \
  23.     strlen(argv[i])>2 ? argv[i]+2 : argv[++i]
  24.  
  25. int mode;
  26.  
  27. main(argc,argv)
  28. int argc;
  29. char **argv;
  30.    {
  31.    register int i,j;
  32.    int w=0,h=0,d=0,size;
  33.    int x=0, y=0;
  34.    int no_head = 0;
  35.    int reverse=0;
  36.    int shape=0;
  37.    int margin=0;
  38.    int wx,wy,border;
  39.    int clean();
  40.  
  41.    ckmgrterm( *argv );
  42.  
  43.    /* check arguments */
  44.  
  45.    for(i=1;i<argc;i++) {
  46.       if (*argv[i] == '-')
  47.          switch (argv[i][1]) {
  48.             case 'x':                /* starting x position */
  49.                x = atoi(GET_OPT(i));
  50.             case 'y':                /* starting y position */
  51.                y = atoi(GET_OPT(i));
  52.                break;
  53.             case 'r':                /* flip bits */
  54.                reverse++;
  55.                break;
  56.             case 's':                /* reshape window */
  57.                shape++;
  58.                break;
  59.             case 'm':                /* margin for -s */
  60.                margin = atoi(GET_OPT(i));
  61.                break;
  62.             default:
  63.                fprintf(stderr,"%s: bad flag %c ignored\n",argv[0],argv[i][1]);
  64.             }
  65.       else if (!no_head){
  66.          no_head++;
  67.          w = atoi(argv[i]);
  68.          }
  69.       else if (h==0)
  70.          w = atoi(argv[i]);
  71.       else
  72.          fprintf(stderr,"%s: invalid argument %s ignored\n",argv[0],argv[i]);
  73.       }
  74.  
  75.    /* get header */
  76.  
  77.    if (no_head) {
  78.       size = ((w+15)&~15)/8;  /* round to 16 bit boundary (rash assumption) */
  79.       }
  80.    else {
  81.       if (!bitmaphead( stdin, &w, &h, &d, &size )) {
  82.          fprintf(stderr,"%s: invalid bitmap format \n",*argv);
  83.          exit(2);
  84.      }
  85.       }
  86.  
  87.    m_setup(0);
  88.  
  89.    ioctl(fileno(m_termout),TIOCLGET,&mode);
  90.    mode |= LLITOUT;
  91.  
  92.    signal(SIGINT,clean);
  93.    signal(SIGTERM,clean);
  94.    signal(SIGHUP,clean);
  95.    get_size(&wx,&wy,0,0);
  96.    get_param(0,0,0,&border);
  97.  
  98.    ioctl(fileno(m_termout),TIOCLSET,&mode);
  99.  
  100.    if (reverse)
  101.       m_func(B_COPYINVERTED);
  102.    else
  103.       m_func(B_COPY);
  104.  
  105.    if (shape) {
  106.       border += margin;
  107.       m_shapewindow(wx,wy,w+2*border,h+2*border);
  108.       m_movecursor(wx+20,0);
  109.       m_flush();
  110.       }
  111.  
  112.    while(!feof(stdin) && h-- > 0) {
  113.       m_bitld(w,1,margin+x,margin+y,size);
  114.       i = size;
  115.       while (i-- > 0 && !feof(stdin))
  116.          fputc(getchar(),m_termout);
  117.       while(i-- > 0)
  118.             fputc('\0',m_termout);
  119.       m_flush();
  120.       y++;
  121.       }
  122.  
  123.    clean(0);
  124.    }
  125.  
  126. clean(n)
  127. int n;
  128.    {
  129.    mode &= ~LLITOUT;
  130.    ioctl(fileno(m_termout),TIOCLSET,&mode);
  131.    exit(n);
  132.    }
  133.